home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
PublicDomain
/
Anwendungen
/
MSCalendar
/
src.lzh
/
Src
/
cal.c
next >
Wrap
C/C++ Source or Header
|
1991-06-07
|
26KB
|
872 lines
/* MSCalendar ! A little FreeWare-Utility from Markus Stipp
(c) Copyright 1991 by Markus Stipp, All Rights reserved.
$Revision: 1.10 $
$Author: mstipp $
$Date: 91/06/07 13:33:36 $
$Log: cal.c,v $
* Revision 1.10 91/06/07 13:33:36 mstipp
* Bug with -f fixed (seems to work now)
* Now uses RawKeyConvert() for Keys
*
* Revision 1.9 91/05/30 18:03:11 mstipp
* V1.08 always switched to current date if Clockwindow was open
*
*/
/*---------------------------------------------------------------------*/
/* Prototypes / Structures / Variables etc. */
/*---------------------------------------------------------------------*/
#include "cal.h"
void Today(void);
void PrintClock(void);
void PrintCal(int month, int year);
void InitWindow(void);
void DrawLine(int x1, int y1, int x2, int y2);
void HandleKeys(USHORT code,USHORT qual,APTR address);
void Iconify(void);
void UnIconify(void);
int DOW(int day, int month, int year);
void CleanUp(int error, char* Message);
TM *GetTime(void);
int atoi(char *string);
int strlen(char *string);
void exit(int error);
void InitMain(void);
void GetVals(void);
void CheckVals(void);
void DoMain(void);
static IBASE *IntuitionBase = NULL;
static GFXBASE *GfxBase = NULL;
struct Library *IconBase = NULL;
struct ConsoleDevice *ConsoleDevice = NULL;
struct IOStdReq ioreq;
CAL cal;
TM *tp;
MSGP *timeport;
TR tr;
BYTE BHeight;
UWORD FHeight,FWidth,FWidth2,BLine,BLine2;
BOOL gadget,winactive,tdevice,current = FALSE;
TF *FontBuf;
SCR scrbuf;
#ifdef GERMAN
char *monthname[] =
{
"Januar ","Februar ","März ","April ","Mai ",
"Juni ","Juli ","August ","September","Oktober ",
"November ","Dezember "
};
#else
char *monthname[] =
{
"January ","February ","March ","April ","May ",
"June ","July ","August ","September","October ",
"November ","December "
};
#endif
USHORT daytab[] =
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
/*---------------------------------------------------------------------*/
/* The main Programs ! */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* If started from WB */
/*---------------------------------------------------------------------*/
int wbmain(struct WBStartup *wbs)
{
/* Variables */
struct DiskObject *dobj;
char **toolsarray;
char *s;
int val;
BPTR olddir;
InitMain();
IconBase = OpenLibrary("icon.library",33);
if(IconBase == NULL)
CleanUp(RETURN_FAIL,"Can't open Icon.Library");
olddir = CurrentDir(wbs->sm_ArgList->wa_Lock);
if(dobj= (struct DiskObject *) GetDiskObject(wbs->sm_ArgList->wa_Name));
{
toolsarray = (char **)dobj->do_ToolTypes;
if(s=(char *)FindToolType(toolsarray,"FLAGS"))
{
if(MatchToolValue(s,"BEEP"))
cal.Beep = TRUE;
if(MatchToolValue(s,"FRONT"))
cal.Front = TRUE;
if(MatchToolValue(s,"ICONIFY"))
cal.Iconify = TRUE;
}
if(s=(char *)FindToolType(toolsarray,"XPOS"))
{
val = atoi(s);
cal.xpos = val;
}
if(s=(char *)FindToolType(toolsarray,"YPOS"))
{
val = atoi(s);
cal.ypos = val;
}
if(s=(char *)FindToolType(toolsarray,"IXPOS"))
{
val = atoi(s);
cal.ixpos = val;
}
if(s=(char *)FindToolType(toolsarray,"IYPOS"))
{
val = atoi(s);
cal.iypos = val;
}
FreeDiskObject(dobj);
}
CurrentDir(olddir);
CloseLibrary(IconBase);
DoMain();
CleanUp(0,NULL);
} /* wbmain */
/*---------------------------------------------------------------------*/
/* If started from CLI */
/*---------------------------------------------------------------------*/
int main(int ac, char **av)
{
/* Variables */
char *ptr;
int i;
LONG val;
InitMain();
/***** Parse the given arguments *****/
for(i = 1; i < ac; ++i)
{
ptr = av[i];
val = atoi(ptr+2);
if(*ptr != '-')
goto def;
switch (ptr[1])
{
case 'x':
cal.xpos = val;
break;
case 'y':
cal.ypos = val;
break;
case 'u':
cal.ixpos = val;
break;
case 'v':
cal.iypos = val;
break;
case 'i':
cal.Iconify = TRUE;
break;
case 'b':
cal.Beep = TRUE;
break;
case 'f':
cal.Front = TRUE;
break;
default: def:
#ifdef GERMAN
printf("\nMSCalendar V%d.%02d GERMAN, " __DATE__ "\n",RELEASE,REVISION);
printf("(c)Copyright 1991 by Markus Stipp, All Rights Reserved\n\n");
printf(" Usage: %s [-Option] [-Option] [...]\n\n",av[0]);
printf(" -x### X-Position vom Kalender (default 0)\n");
printf(" -y### Y-Position vom Kalender (default 0)\n");
printf(" -u### X-Position vom kleinen Fenster (default 0)\n");
printf(" -v### Y-Position vom kleinen Fenster (default 0)\n");
printf(" -b Bei vollen Stunden blitzen\n");
printf(" -f Kleines Fenster immer im Vordergrund\n");
printf(" -i Mit kleinem Fenster starten\n\n");
#else
printf("\nMSCalendar V%d.%02d, " __DATE__ "\n",RELEASE,REVISION);
printf("(c)Copyright 1991 by Markus Stipp, All Rights Reserved\n\n");
printf(" Usage: %s [-option] [-option] [...]\n\n",av[0]);
printf(" -x### X-Position of the Calendar (default 0)\n");
printf(" -y### Y-Position of the Calendar (default 0)\n");
printf(" -u### X-Position of the iconified Window (default 0)\n");
printf(" -v### Y-Position of the iconified Window (default 0)\n");
printf(" -b Beep at full hours\n");
printf(" -f Put the iconified window always to front\n");
printf(" -i Start with iconified Window\n\n");
#endif
CleanUp(0,NULL);
break;
} /* switch */
} /* for */
DoMain();
} /* main */
/*---------------------------------------------------------------------*/
/* Open Libraries etc. */
/*---------------------------------------------------------------------*/
void InitMain(void)
{
cal.Iconify = cal.Beep = cal.Front = FALSE; /* Default for startup */
/***** Open Libraries *****/
IntuitionBase = (IBASE *) OpenLibrary("intuition.library",33);
GfxBase = (GFXBASE *) OpenLibrary("graphics.library",33);
if (GfxBase == NULL || IntuitionBase == NULL)
CleanUp(RETURN_FAIL,"Can't open Graphics- or Intuition.Library");
/***** Create a MessagePort for the Timer.Device *****/
timeport = CreatePort(NULL,0);
if(timeport == NULL)
CleanUp(RETURN_FAIL,"Can't create Port");
/***** Open the Timer.Device *****/
if(OpenDevice("timer.device",UNIT_MICROHZ,(IOR *) &tr,0L))
CleanUp(RETURN_FAIL,"Can't open Timer.Device");
tdevice = TRUE;
/***** Open Console Device for RawKeyConvert() *****/
if(OpenDevice("console.device",-1L,(IOR *) &ioreq,0L))
CleanUp(RETURN_FAIL,"Can't open Console.Device");
ConsoleDevice = (struct ConsoleDevice *)ioreq.io_Device;
cal.xpos = cal.ypos = cal.ixpos = cal.iypos = 0;
} /* InitMain */
/*---------------------------------------------------------------------*/
/* Get the Screen's data and set some Variables. */
/*---------------------------------------------------------------------*/
void GetVals(void)
{
Delay(10); /* If someone changes the Font, we must wait a bit */
Forbid();
if(!(GetScreenData(&scrbuf,sizeof(SCR),WBENCHSCREEN,NULL)))
CleanUp (RETURN_FAIL,"Can't get ScreenData");
Permit();
FontBuf = (TF *) OpenFont(scrbuf.Font);
BHeight = scrbuf.BarHeight+1;
FHeight = GfxBase->DefaultFont->tf_YSize;
FWidth = GfxBase->DefaultFont->tf_XSiz